/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.promo.impl;

import dao.promo.PromoDistrukDao;
import java.util.List;
import java.util.Map;
import model.promo.PromoDistruk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.promo.PromoDistrukService;
import utility.NameValueList;
import utility.StringUtils;

/**
 *
 * @author Lalugina
 */

@Service("promoDistrukService")
@Transactional(readOnly=true)
public class PromoDistrukServiceImpl implements PromoDistrukService{

    String mainQuery = "select promoDistruk from PromoDistruk promoDistruk "+
               "left join fetch promoDistruk.promo promo";
    
    @Autowired private PromoDistrukDao dataDao;
    
    @Override
    @Transactional(readOnly=false)
    public boolean save(PromoDistruk data) {
        return dataDao.save(data);
    }

    @Override
    @Transactional(readOnly=false)
    public boolean delete(PromoDistruk data) {
        return dataDao.delete(data);
    }

    @Override
    public PromoDistruk get(int id) {
        String query = mainQuery+" where promoDistruk.id = "+id;
        return dataDao.getByCustomQuery(query);
    }

    @Override
    public Long count(Map<NameValueList, Object> params) {
        String query= "select count(*) from PromoDistruk promoDistruk "+StringUtils.getFilter(params);
        return dataDao.count(query);
    }

    @Override
    public List<PromoDistruk> getAll(int promoId) {
        String query = mainQuery+" where promoDistruk.promo.id = "+promoId;
        return dataDao.getAll(query);
    }

    
}
